/*
 * @Author: 陈德基
 * @Date: 2021-06-10 15:10:21
 * @LastEditTime: 2021-11-15 16:05:54
 * @Description: 
 * 1，点击两次退出
 * 
 * @FilePath: \copy_gsy_github_app_flutter\lib\page\main\widgets\base_index_page.dart
 * 联系方式：
 * wx: melody_2009
 * qq: 7815171323 
 */

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '../controllers/controller.dart';

abstract class BaseIndexPageWidget extends GetView<MainController> {
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        return exitApp();
      },
      child: buildIndexPage(),
    );
  }

  Future<bool> exitApp() async {
    var result = controller.exitApp();
    if (!result) {
      clickAgainExit();
    } else {
      await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
    }
    return result;
  }

  /// 顶层应用定义如何提示用户再次点击退出应用
  clickAgainExit();

  Widget buildIndexPage();
}
